<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ include file="/taglibs.jsp"%>
<!-- 月历 -->
<link rel="stylesheet" type="text/css" href="<%=application.getContextPath() %>/css/smoothness.datepick.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/css/ui.jqgrid.css" />
<link href="/css/ddaccordion.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" charset="UTF-8" src="<%=application.getContextPath() %>/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="<%=application.getContextPath() %>/js/jquery.datepick-zh-CN.js"></script>
<script src="/js/grid.locale-en.js" type="text/javascript"></script>
<script src="/js/jquery.jqGrid.min.js" type="text/javascript" charset="UTF-8"></script>
<s:url var="supplierPops" value="/json/supplierPops.do"/>
<s:url var="brandPops" value="/json/brandPops.do"/>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath()%>'/>
<script type="text/javascript" charset="UTF-8" src="<%=ServerValue.getMidContextPath()%>/js/jquery.alphanumeric.js"></script>
<script language="javascript">
	var content;
	var qry_target = '01';
	$().ready( function() {

		$("#cbAll").click(function(){
			$(":input[id*=cb_]").attr('checked',$("#cbAll").attr('checked'));
		});
		
		$("#shelfProductIdParam").numeric();
		$("#addonProductIdParam").numeric();
		$("#supplierIdParam").numeric();
		$("#getSupplier").click(function() {
			doAR('${supplierPops}', 'dialog'); 
			openDialog('供应商搜寻',content, 550, 440);
		});
		//$("#brandIdParam").numeric();
		$("#getBrand").click(function() {
			doAR('${brandPops}', 'dialog'); 
			openDialog('品牌搜寻',content, 550, 440);
		});	
		$('#startDateParam').datepick({minDate: new Date(${minDate}), maxDate:new Date(${today}),showOn:'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"}); 
		$('#endDateParam').datepick({minDate: new Date(${minDate}), maxDate:new Date(${today}),beforeShow:customRange,showOn: 'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"});
		$("#productForm").submit(function(){
			if ( 0 == $(":checkbox[name='prdtDelete']:checked").size() ){
				alert("请勾择要修改的商品");
				return false;
			} 
			if ( "" == $("#productAttributeA").val() && "" == $("#productAttributeB").val() ){
				alert("请选择商品属性");
				return false;
			}
			if(""!=$("#productAttributeA").val()){
				$("#productAttributeB").val($("#productAttributeA").val());
			}
			return true;
		});		

		//load default value
		if ( "" != "${categoryLevel1Param}"){ 
			$('#elementSelect').find('option').remove().end();
			$("#categorySelect option[value='${categoryLevel1Param}']").attr('selected', 'selected');  
			$.post("${midContextPath}/category/getProductCategory.do",{categoryid:"${categoryLevel1Param}"},elementSelectCallback,"json");
		}
		
		$("#categorySelect").click(function(){
			if ( "" != $(this).val()  ){
				$.ajax({
				    url: '${midContextPath}/category/getProductCategory.do',
				    type: 'post',
				    dataType: 'json',
				    data: {categoryid:$(this).val(), callback: 'elementSelectCallback'},
				    cache: false,
				    beforeSend: function(xhr) {
							$('#elementSelect').find('option').remove().end();
				    },
				    complete:function(){
				    },
				    success: function( strData ){
				    	elementSelectCallback(strData);
					}
				});
			}
		});		
	});
	function elementSelectCallback(categories){
		$('#elementSelect').append($("<option></option>").attr("value","").text("--请选择--"));
		for( var i = 0 ; i < categories.length; i++ ){
				$('#elementSelect').append($("<option></option>").attr("value",categories[i].id).text(categories[i].name));
		}
		if ( "" != "${categoryLevel2Param}" )
			$("#elementSelect option[value='${categoryLevel2Param}']").attr('selected', 'selected');
	}	
	function customRange (){
		var startDt = $('#startDateParam').val(); //起始日
		var endDt = new Date(parseInt(startDt.substring(0,4),10),parseInt(startDt.substring(5,7),10)-1,parseInt(startDt.substring(8,10),10)); //結束日
		return {minDate:endDt,maxDate: new Date(${today})}; 
	}
</script>
<style type="text/css">
    .bg-active {
        background: #D4FAED;
    }
</style>
<h1>N选M商品管理<br/>
	<div class="f-link">
		<a href="editProduct.do?productIdParam=">新增N选M商品</a>
	</div>
</h1>
<s:actionerror />
<s:actionmessage />
<s:fielderror />
<br/>
<div class="data-form">
	<s:form action="search.do" method="post">
		<b>活动商品编号：</b>
		<input name="mainProductIdParam" id="shelfProductIdParam" type="text" title="活动商品编号" maxlength="8" value="${mainProductIdParam}">
		<b>活动商品名称关键字：</b>
		<input name="promoteNameParam" id="promoteNameParam" type="text" title="活动商品名称关键字" value="${promoteNameParam}">
		<b>销售状态：</b>
    <s:select name="productAttributeParam" list="attributeMenu.options" listKey="key"  listValue="value.name"/>
		<br/>
		 <b>搭配商品编号:</b>
		<input name="addonProductIdParam" id="addonProductIdParam" type="text" title="搭配商品编号" value="${addonProductIdParam}"> 
		<b>活动起迄时间：</b>
		<input name="startDateParam" type="text" id="startDateParam" value="${startDateParam}" size="10" maxlength="10"> ~
    <input name="endDateParam" type="text" id="endDateParam" value="${endDateParam}" size="10" maxlength="10">
    <b>供应商编号：</b>
		<s:textfield name="supplierParam" id="supplierIdParam" maxlength="6"/>
		<img class="ui-icon ui-icon-search" src="/images/none.gif" style="height:16px; width:16px; position:relative; display:inline;" 
			id="getSupplier"/>
	 <br/>		
	<b>品牌编号：</b> 
	<s:textfield name="brandParam" id="brandIdParam" />
	<img class="ui-icon ui-icon-search" src="/images/none.gif" style="height:16px; width:16px; position:relative; display:inline;" 
		id="getBrand"/>  
  	<b>主要负责PM：</b>
  	<s:select id="pmParam" name="pmParam" list="users" listKey="username"  listValue="nameNative" headerKey="" headerValue="--请选择--"/>
		<b>PM所属单位：</b>
		<s:select id="organizationParam" name="organizationParam" list="groups" listKey="code"  listValue="description" headerKey="" headerValue="--请选择--"/>
		<br/>
		<b>馆别：</b>
		<select id="categorySelect" name="categoryLevel1Param">
				<option value="">--请选择--</option>
       	<c-rt:forEach items="${rootCategories}" var="category">
				<option value="${category.id}">${category.name}</option>
			</c-rt:forEach>
    </select>
    <select id="elementSelect" name="categoryLevel2Param">
    	<option value="">--请选择--</option>
    </select>    
    <b>转单状态：</b> 	
    <select id="isScmParam" name="isScmParam">
		<option value="" ${empty isScmParam ? 'selected': ''}>--全部--</option>
		<option value="B" ${isScmParam=='B' ? 'selected': ''}>BO</option>
		<option value="Y" ${isScmParam=='Y' ? 'selected': ''}>SCM</option>
		<option value="N" ${isScmParam=='N' ? 'selected': ''}>进仓</option>
    </select>
   <b>退换货条件：</b>
   <s:select id="returnRule" name="returnRule" list="returnRuleMenu.options" listKey="key"  listValue="value.name" headerKey="" headerValue="--全部--" />
   <b>限立即购买：</b>
   <select name="nmMustOrderBuyParam" id="nmMustOrderBuyParam" title="限立即购买">
		<option value="" ${empty nmMustOrderBuyParam ? 'selected': ''}>--全部--</option>
		<option value="Y" ${nmMustOrderBuyParam=='Y' ? 'selected': ''}>是</option>
		<option value="N" ${nmMustOrderBuyParam=='N' ? 'selected': ''}>否</option>
	</select>
		<input type="button" value="搜寻" onclick="this.form.submit();" />
	</s:form>
</div>
<p></p>
<yaodian100:pageutil link="search.do${queryString}" pagerObj="${pager}" />
<s:form action="editProductAttribute.do" method="post" id="productForm">
	<s:select id="productAttributeA" list="attributeMenu.options" listKey="key"  listValue="value.name" headerKey="" headerValue="---请选择销售状态---"/>
	<input type="submit" value="批次修改"/><br/>	
	<table class="tb-1" width="100%">
		<thead>
			<tr>
	      <th><input type="checkbox" id="cbAll" /></th>
	      <th>商品图</th>
	      <th>商品编号</th>
	      <th>商品名称</th>
				<th>任选商品数</th>
				<th>上架销售价格</th>
				<th>供应商</th>
				<th>销售状态</th>
				<th>转单<br/>状态</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		<c-rt:forEach items="${pickProductList}" var="pickProduct" varStatus="rows_index">
			 <tr>
				        <td><input name="prdtDelete" type="checkbox" value="${pickProduct['product_id']}" id="cb_${rows_index.count}"/></td>
				        <td><img onError="this.src='/PImg/blank_75.gif'" src="/PImg/${fn:substring(pickProduct['product_id'],0,4)}/${pickProduct['product_id']}/${pickProduct['product_id']}_m75.jpg"/></td>
				        <td><a href="<%=ServerValue.getMidContextPath()%>/pickProduct2/editProduct.do?productIdParam=${pickProduct['product_id']}" />${pickProduct['product_id']}</a></td>
				        <td>
				        <c-rt:choose>
								   	<c-rt:when test="${fn:length(pickProduct['product_name']) > 18}">
								   		${fn:substring(pickProduct['product_name'],0,18)}...
								   	</c-rt:when>
								   	<c-rt:otherwise>${pickProduct['product_name']}</c-rt:otherwise>
								  </c-rt:choose>
				        </td>
								<td>${pickProduct['pickup_qty']}</td>
								
								<td>
								<fmt:formatNumber value="${pickProduct['on_price']}" pattern="######.0"/>
								<c-rt:if test="${pickProduct['on_price'] eq ''}">
								<fmt:formatNumber value="${pickProduct['last_price']}" pattern="######.0"/>
								</c-rt:if>
								</td>
								<td>
										${pickProduct['companyname']}
								</td>
								<td>
									<c-rt:if test="${pickProduct['is_delete'] eq 'Y'}">已删除 (不可查询,不可销售)</c-rt:if>
									<c-rt:if test="${pickProduct['is_delete'] eq 'N'}">未删除 (可查询,可销售)</c-rt:if>
									<c-rt:if test="${pickProduct['is_delete'] eq 'Q'}">可查询,不可销售(Queryable)</c-rt:if>
									<c-rt:if test="${pickProduct['is_delete'] eq 'H'}">不可查询,可销售(Hidden)</c-rt:if>
								</td>
								<td>
								<c-rt:if test="${pickProduct['is_scm'] eq 'Y'}">SCM</c-rt:if>
									<c-rt:if test="${pickProduct['is_scm'] eq 'N'}">进仓</c-rt:if>
									<c-rt:if test="${pickProduct['is_scm'] eq 'B'}">BO</c-rt:if>
								</td>				
								<td>
								<c-rt:if test="${pickProduct['step_flag'] eq '1'}">
									<a href="<%=ServerValue.getMidContextPath()%>/pickProduct2/editProduct.do?productIdParam=${pickProduct['product_id']}" />设置主档</a>
									<br/>
								</c-rt:if>
								<c-rt:if test="${pickProduct['step_flag'] eq '2'}">
									<a href="<%=ServerValue.getMidContextPath()%>/pickProduct2/editProduct.do?productIdParam=${pickProduct['product_id']}" />设置主档</a>
									<br/>
										  <a href="<%=ServerValue.getMidContextPath()%>/image2/edit.do?productId=${pickProduct['product_id']}">设置图档</a> 
								</c-rt:if>
								<c-rt:if test="${pickProduct['step_flag'] eq '3'}">
									<a href="<%=ServerValue.getMidContextPath()%>/pickProduct2/editProduct.do?productIdParam=${pickProduct['product_id']}" />设置主档</a>
									<br/>
										  <a href="<%=ServerValue.getMidContextPath()%>/image2/edit.do?productId=${pickProduct['product_id']}">设置图档</a> 
									<br/>
									<a href="<%=ServerValue.getMidContextPath()%>/pickProduct2/editPickProduct.do?productIdParam=${pickProduct['product_id']}">设置商品</a>						 
								</c-rt:if>	
								<c-rt:if test="${pickProduct['step_flag'] eq '4'}">
									<a href="<%=ServerValue.getMidContextPath()%>/pickProduct2/editProduct.do?productIdParam=${pickProduct['product_id']}" />设置主档</a>
									<br/>
										  <a href="<%=ServerValue.getMidContextPath()%>/image2/edit.do?productId=${pickProduct['product_id']}">设置图档</a> 
									<br/>
									<a href="<%=ServerValue.getMidContextPath()%>/pickProduct2/editPickProduct.do?productIdParam=${pickProduct['product_id']}">设置商品</a>						 
									<br/>
									<a href="<%=ServerValue.getMidContextPath()%>/pickProduct2/shelfSearch.do?productIdParam=${pickProduct['product_id']}" />设置上下架</a>
								</c-rt:if>	
								</td>
		 		 </tr>  
		</c-rt:forEach>
		
		</tbody>
	</table>
	<br />
	<s:select id="productAttributeB" name="productAttribute" list="attributeMenu.options" listKey="key"  listValue="value.name" headerKey="" headerValue="---请选择销售状态---"/>
	<input type="submit" value="批次修改"/>	
</s:form>
<yaodian100:pageutil link="search.do${queryString}" pagerObj="${pager}" />
